package com.example.cinema.toolclass;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.Log;
import android.view.View;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

//View 转Bitmap并保存
public class ViewBitmapFile {

    public void convert(View view, Context context)
    {
        int w = view.getWidth();
        int h = view.getHeight();
        Bitmap bmap = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bmap);
        canvas.drawColor(Color.WHITE);
        view.draw(canvas);
        try {
            FileOutputStream Fos = context.openFileOutput("spread.png",Context.MODE_APPEND);
            bmap.compress(Bitmap.CompressFormat.PNG,100,Fos);

            File file = new File(context.getFilesDir(),"spread.png");
            if(file.exists())
            {
                Log.i("OOOO","图片已存在");
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
